﻿Partial Class Paginas_InscribirUnConvenio
    Inherits System.Web.UI.Page

#Region "Declaracion de Funciones y Procedimientos de pagina"
    Private Sub CargarInfoConvenio()
        Dim objNegConv As New dllNegocio.NegConvenios(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objConv As New dllEntidades.clsConvenio
        Try
            myCollect = objNegConv.ListarConvenios(Me.hdnIdConvenio.Value.Trim, "TODOS", 0)
            If myCollect.Count > 0 Then
                objConv = myCollect.Item(1)
                Me.lblConvenio.Text = objConv.Nombre
                Me.lblFecHoraIni.Text = objConv.FechaHoraInicio.ToString
                Me.lblFecHoraFin.Text = objConv.FechaHoraFinal.ToString
                Me.hdnImagen.Value = objConv.ImagenMail
                If objConv.CodigoTipoAsistente = 3 Then
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("5", 5))
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("4", 4))
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("3", 3))
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("2", 2))
                ElseIf objConv.CodigoTipoAsistente = 1 Then
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("1", 1))
                ElseIf objConv.CodigoTipoAsistente = 2 Then
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("2", 2))
                End If
            End If
            Call CargarGrillaLugaresConvenio()
        Catch ex As Exception
        Finally
            objNegConv.Dispose()
            objNegConv = Nothing
            myCollect = Nothing
            objConv.Dispose()
            objConv = Nothing
        End Try
    End Sub

    Private Sub CargarGrillaLugaresConvenio()
        Dim objNegConvLug As New dllNegocio.NegLugaresConvenios(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection

        Try
            myCollect = objNegConvLug.ListarLugaresDeConvenio(Me.hdnIdConvenio.Value.Trim)
            Me.GrillaResultados.DataSource = myCollect
            Me.GrillaResultados.DataBind()
        Catch ex As Exception
        Finally
            myCollect = Nothing
            objNegConvLug.Dispose()
            objNegConvLug = Nothing
        End Try
    End Sub
#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.hdnIdConvenio.Value = Request.QueryString("ConvenioID")
            Call CargarInfoConvenio()
        End If
    End Sub

    Protected Sub btnVolver_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVolver.Click
        Response.Redirect("InscribirConvenio.aspx?PostBack=SI")
        Response.End()
    End Sub

    Protected Sub btnInscribir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInscribir.Click
        Dim objNegConv As New dllNegocio.NegConvenios(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objConv As New dllEntidades.clsConvenio
        Dim objFunc As New dllEntidades.clsFuncionario
        Dim rutaImg As String = Server.MapPath("~")
        rutaImg = rutaImg & IIf(Right(rutaImg.ToString.Trim, 1) = "\", "", "\") & "Paginas\Img\ImgLoad\Convenios\" & Me.hdnImagen.Value.Trim
        Dim objServidor As New dllNegocio.NegMail()

        Try
            objServidor.CorreoDesde = System.Configuration.ConfigurationManager.AppSettings.Get("CorreoDesde")
            objServidor.ServidorMail = System.Configuration.ConfigurationManager.AppSettings.Get("ServidorMail")
            objConv.Codigo = Me.hdnIdConvenio.Value.Trim
            objFunc.Rut = Session("RutUsuario")
            If objNegConv.InscribirConvenio(objConv, objFunc, rutaImg, objServidor, Me.ddlNumAsis.SelectedItem.Value) = True Then
                Dim myPagina As String = "CuponConvenio.aspx?ConvenioID=" & Me.hdnIdConvenio.Value.Trim & "&CantAsis=" & Me.ddlNumAsis.SelectedItem.Value.Trim
                UtilidadesPagina.EjecutaScript("AbrirPopup('" & myPagina & "');", Me.Page)
            End If
        Catch ex As Exception
        Finally
            objNegConv.Dispose()
            objNegConv = Nothing
            myCollect = Nothing
            objConv.Dispose()
            objConv = Nothing
            objServidor.Dispose()
            objServidor = Nothing
        End Try
    End Sub
End Class
